
angular.module('mamApp').controller('programPlayController', ['$scope', 'AlbumPlayManager', '$state','api','paramsManager',
    function ($scope, AlbumPlayManager, $state,api,paramsManager) {
        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            key: $state.params.key || "",
            field:$state.params.field||"",
            sortType:$state.params.sortType||"",
            value: $state.params.value || '',
            "X-Auth-Token":$scope.userInfo.token
        };

        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        };

        $scope.sortClick=function (field) {
            if($scope.search.field==field){
                $scope.search.sortType=$scope.search.sortType=="desc"?"asc":"desc";
                $state.go($state.current.name, $scope.search)
            }else{

                $scope.search.field=field;
                $scope.search.sortType="desc";
                $state.go($state.current.name, $scope.search)

            }


        }

        $scope.selectTerms = [
            {key: "", value: "选择条件"},
            {key: "albumName", value: "专辑名称"},
            {key: "programName",value: "节目名称"}
        ];

        $scope.downHref=api+"/admin/stat/play/program/excel"+paramsManager.query($scope.search);

        $scope.findData=function(){
            AlbumPlayManager.programPlay([$scope.search.pageNo, $scope.search.pageSize], $scope.search).then(function (result) {
                $scope.programPlayList = result.data.pageList;
                $scope.paginationConf.totalItems = result.data.total;
            })
        }

        AlbumPlayManager.programPlay([$scope.search.pageNo, $scope.search.pageSize], $scope.search).then(function (result) {
            if(result.data.c=="n"){
                $scope.noPermission=true;
            }else{
                $scope.noPermission=false;
                $scope.programPlayList = result.data.pageList;
                $scope.paginationConf.totalItems = result.data.total;
            }

        })

    }]);
